<?php

class class_chart {

    private $title = '天高智慧';
    private $labels = array();
    private $elements = array();

    private $y_max = 0;
    private $y_min = 0;

    public function setTitle($title) {
        $this->title = $title;
    }

    public function setLabels($labels) {
        $this->labels = $labels;
    }

    public function addElement($text,$color,$values=array()) {
        if (@max($values) > $this->y_max) $this->y_max = @max($values)+10;
        if (@min($values) < $this->y_min && $this->y_min != 0) $this->y_min = @min($values)-10;
        $this->elements[] = array('type'=>'line','text'=>$text,'colour'=>$color,'width'=>2,'font-size'=>13,'dot-size'=>3,'values'=>$values ?$values:array(0));
    }

    public function getJson() {
        $data = array();
        $data['title'] = array('text'=>$this->title,'style'=>'{color:#9933cc;font-family:微软雅黑,宋体;font-size:15px;}');
        $data['x_axis'] = array('labels'=>array('labels'=>$this->labels),'3d'=>true,'steps'=>50,'offset'=>10);
        if ($this->elements) $data['elements'] = $this->elements;
        $data['y_axis'] = array('max'=>$this->y_max,'min'=>$this->y_min,'steps'=>10,'text'=>'abc','3d'=>true);

        return json_encode($data);
    }
}